package abd.pr1.Controllers;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;

import javax.sql.DataSource;

import abd.pr1.Interface.BuscarSeriesPanel;
import abd.pr1.Interface.SerieWindow;
import abd.pr1.Mappers.SeriesMapper;
import abd.pr1.Models.Serie;
import abd.pr1.Models.Usuario;


public class BuscarSeriesPanelController implements ActionListener {

	private MainWindowController mainWindowController;
	private BuscarSeriesPanel buscarSeriesPanel;
	private DataSource ds;
	private Usuario user;
	
	public BuscarSeriesPanelController(MainWindowController mainWindowController,BuscarSeriesPanel buscarSeriesPanel, DataSource ds, Usuario user) {

		this.mainWindowController = mainWindowController;
		this.buscarSeriesPanel = buscarSeriesPanel;
		this.ds = ds;
		this.user = user;
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		if (e.getActionCommand().equals("buscar_serie")){
			List<Serie> series=new SeriesMapper(ds).buscarNombreSerie(buscarSeriesPanel.getBuscarTexto());
			this.buscarSeriesPanel.setListaseries(series);
		}else if (e.getActionCommand().equals("info_serie")){
			Serie serie = buscarSeriesPanel.getSelectedSerie();
			if(serie!=null){
				new SerieWindowController(mainWindowController, new SerieWindow(), ds, user, serie);
			}
		}
		
		

	}

}
